from PIL import Image
import math
def decode(im):
    width,height=im.size
    lst=[]
    for y in range(height):
        for x in range(width):
            red,green,blue=im.getpixel((x,y))
            if(red|green|blue)==0:
                break
            index =(green<<8)+blue
            lst.append(chr(index))
    return ''.join(lst)
if __name__ =='__main__':
    all_text=decode(Image.open('三国演义.bmp','r'))
    with open('三国演义p.txt','w',encoding='UTF-8') as f:
        f.write(all_text)